#include <stdio.h>
#include <math.h>

#define N 11
int main()
{
    int dp[N][N][N][N] = {0};
    int a[N][N] = {0};
    int n, x, y, z;
    scanf("%d", &n);
    while (1)
    {
        scanf("%d %d %d", &x, &y, &z);
        if (!x && !y && !z)
        {
            break;
        }
        a[x][y] = z;
    }
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= n; j++)
        {
            for (int k = 1; k <= n; k++)
            {
                for (int l = 1; l <= n; l++)
                {
                    if (i == k && j == l)
                    {
                        dp[i][j][k][l] = fmax(fmax(dp[i - 1][j][k - 1][l], dp[i][j - 1][k - 1][l]), fmax(dp[i - 1][j][k][l - 1], dp[i][j - 1][k][l - 1])) + a[k][l];
                    }
                    else
                    {
                        dp[i][j][k][l] = fmax(fmax(dp[i - 1][j][k - 1][l], dp[i][j - 1][k - 1][l]), fmax(dp[i - 1][j][k][l - 1], dp[i][j - 1][k][l - 1])) + a[i][j] + a[k][l];
                    }
                }
            }
        }
    }
    printf("%d",dp[n][n][n][n]);
}
